<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
//内容页默认控制器
class ContentController extends Controller{
	
    //前台首页
    public function index(){

    	//获得顶级分类,导航条
    		$cateModel =  new \Common\Model\Cate;
    		$data = $cateModel->where("pid=0")->get();
		View::with('topCate',$data);
    	
		//显示分类
		$model = new \Common\Model\Cate;
		//树状结构
		$cateData =$model->where("pid=0")->get();
		View::with('cateData',$cateData);
		
		
		//显示内容
		$aid = Q('get.aid',0,'intval');
		$arcModel = new \Common\Model\Arc;
		//刷新浏览次数+1
		$arcModel->where("aid={$aid}")->increment('click',1);
		//UPDATE article SET click=click+1 WHERE aid=$aid;
		//文章和文章数据表关联
		$data = $arcModel->join('article_data','aid','=','article_aid')->where("aid={$aid}")->find();
		$arcData4 = $arcModel->join('category','category_cid','=','cid')->orderBy('sendtime','DESC')->limit(6)->get();
		$arcData5 = $arcModel->join('category','category_cid','=','cid')->orderBy('sendtime','ASC')->limit(6)->get();
		$arcTagModel = new \Common\Model\ArcTag;
		$data['tag'] = $arcTagModel
						   ->join('tag','tag_tid','=','tid')
						   ->where("article_aid={$aid}")
						   ->field('tid,tname')->get();
		View::with('data',$data);
		View::with('arcData4',$arcData4);
		View::with('arcData5',$arcData5);






		//列表页right标签云
		$TagModel = new \Common\Model\Tag;
		$rightTag = $TagModel->get();
		View::with('rightTag',$rightTag);


		//列表页尾部-友情链接
		$LinkModel = new \Common\Model\Link;
		$FootLink = $LinkModel->get();
		View::with('FootLink',$FootLink);


		//列表页最新3篇文章
		$arcModel = new \Common\Model\Arc;
		$arcData = $arcModel->join('category','category_cid','=','cid')->orderBy('sendtime','DESC')->limit(4)->get();
		View::with('arcData',$arcData);


		
		//列表页right分类列表***********
		$cateModel =  new \Common\Model\Cate;
    	$Catedata = $cateModel->get();
    		//实例化文章模型
    	$ArcModel = new \Common\model\Arc;
    	foreach ($Catedata as $k => $v) {
    		$Catedata[$k]['num'] = $ArcModel->where("category_cid={$v['cid']}")->count();
    	}
    	// p($Catedata);
    	View::with('Catedata',$Catedata);








		
		//载入模板
       View::make();
    }

}




